<template>
  <div>
    <el-input
        placeholder="请输入版本内容"
        v-model="version">
    </el-input>

    <el-input
        type="textarea"
        :rows="10"
        placeholder="请输入公告"
        v-model="notice">
    </el-input>
    <el-input
        type="textarea"
        :rows="30"
        placeholder="请输入字典"
        v-model="dictionary">
    </el-input>
    <el-button type="info" plain @click="doUpdate" style="width: 100%">更新信息</el-button>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import apiClient from '@/utils/axios'
import { ElMessage } from 'element-plus'

const version = ref<string>('')
const notice = ref<string>('')
const dictionary = ref<string>('')

const getVersion = () => {
  apiClient.get('/admin/get_version').then((res: any) => {
    if (res.data.status === 200) {
      version.value = res.data.data.version
      notice.value = res.data.data.notice
      dictionary.value = res.data.data.dictionary
      ElMessage({
        message: res.data.msg,
        type: 'success',
        placement: 'top-right',
      })
    } else {
      ElMessage({
        message: res.data.msg,
        type: 'error',
        placement: 'top-right',
      })
    }
  })
}

const doUpdate = () => {
  apiClient
    .put('/admin/update_version', {
      version: version.value,
      notice: notice.value,
      dictionary: dictionary.value,
    })
    .then((res: any) => {
      if (res.data.status === 200) {
        ElMessage({
          message: res.data.msg,
          type: 'success',
          placement: 'top-right',
        })
      } else {
        ElMessage({
          message: res.data.msg,
          type: 'error',
          placement: 'top-right',
        })
      }
    })
}

onMounted(() => {
  getVersion()
})
</script>

<style scoped>
</style>